//
//  GKZYNewsCell.m
//  GKZYAid
//
//  Created by lanou3g on 16/3/1.
//  Copyright © 2016年 GKZYAid. All rights reserved.
//

#import "GKZYNewsCell.h"
#import "GKZYSelectionCell.h"
#define KWidth self.contentView.frame.size.width
#define KHeight self.contentView.frame.size.height
@interface GKZYNewsCell ()

@property (nonatomic,strong)UIImageView *imageName;
@property (nonatomic,strong)UIImageView *imageInto;
@property (nonatomic,strong)UIImageView *imageTime;

@end
@implementation GKZYNewsCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self addViews];
    }
    
    return self;
}

//重写setter方法:
- (void)setModel:(GKZYMessageModel *)model{
    
    self.News_NameLabel.text = model.news_name;
    self.News_IntoLabel.text = model.news_intro;
    self.News_TimeLabel.text = model.news_time;
}

- (void)addViews{
    
    self.imageName = [[UIImageView alloc]init];
    self.imageName.frame = CGRectMake(KWidth * 0.03, KHeight *0.1, KWidth * 0.05, KHeight * 0.2);    self.imageName.image = [UIImage imageNamed:@"messageName"];
    [self.contentView addSubview:self.imageName];
    
    self.News_NameLabel = [[UILabel alloc]init];
    self.News_NameLabel.frame = CGRectMake( KWidth* 0.10 , KHeight * 0.1, KWidth - KWidth * 0.15, KHeight * 0.3);
    self.News_NameLabel.font = [UIFont systemFontOfSize:17];
    self.News_NameLabel.numberOfLines = 0;
    self.News_NameLabel.textColor = [UIColor orangeColor];
    [self.contentView addSubview:self.News_NameLabel];
    
    self.imageInto = [[UIImageView alloc]init];
    self.imageInto.frame = CGRectMake(KWidth * 0.03, KHeight * 0.42, KWidth * 0.05, KHeight * 0.2);
    self.imageInto.image = [UIImage imageNamed:@"messageInto"];
    [self.contentView addSubview:self.imageInto];
    
    self.News_IntoLabel = [[UILabel alloc]init];
    self.News_IntoLabel.frame = CGRectMake(KWidth * 0.10, KHeight * 0.42, KWidth - KWidth * 0.15, KHeight * 0.3);
    self.News_IntoLabel.font = [UIFont systemFontOfSize:15];
    self.News_IntoLabel.numberOfLines = 0;
    self.News_IntoLabel.textColor = [UIColor darkGrayColor];
    [self.contentView addSubview:self.News_IntoLabel];
    
    self.imageTime = [[UIImageView alloc]init];
    self.imageTime.frame = CGRectMake(KWidth * 0.03, KHeight * 0.73 ,KWidth *0.05, KHeight * 0.2);
    self.imageTime.image = [UIImage imageNamed:@"messageTime"];
    [self addSubview:self.imageTime];
    
    self.News_TimeLabel = [[UILabel alloc]init];
    self.News_TimeLabel.frame = CGRectMake(KWidth * 0.10, KHeight * 0.73, KWidth - KWidth * 0.15, KHeight * 0.25);
    self.News_TimeLabel.font = [UIFont systemFontOfSize:12];
    self.News_TimeLabel.numberOfLines = 0;
    self.News_TimeLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:self.News_TimeLabel];
    
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    self.imageName.frame = CGRectMake(KWidth * 0.03, KHeight *0.1, KWidth * 0.05, KHeight * 0.2);
    self.News_NameLabel.frame = CGRectMake( KWidth* 0.10 , KHeight * 0.1, KWidth - KWidth * 0.15, KHeight * 0.3);
    
    self.imageInto.frame = CGRectMake(KWidth * 0.03, KHeight * 0.42, KWidth * 0.05, KHeight * 0.2);
    self.News_IntoLabel.frame = CGRectMake(KWidth * 0.10, KHeight * 0.42, KWidth - KWidth * 0.15, KHeight * 0.3);
    
    //计算文本高度:
    CGRect rect = _News_IntoLabel.frame;
    rect.size.height = [GKZYSelectionCell labelHeightString:_News_IntoLabel.text];
    _News_IntoLabel.frame = rect;
    
    self.imageTime.frame = CGRectMake(KWidth * 0.03, KHeight * 0.73 ,KWidth *0.05, KHeight * 0.2);
    
    self.News_TimeLabel.frame = CGRectMake(KWidth * 0.10, KHeight * 0.73, KWidth - KWidth * 0.15, KHeight * 0.25);
}

//自适应高度:
+ (CGFloat)labelHeightString:(NSString *)string{
    
    CGSize size = CGSizeMake([UIScreen mainScreen].bounds.size.width, 1000);
    
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    
    CGRect rect = [string boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return rect.size.height;
}


- (void)awakeFromNib {
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
